package com.magic.smartcity.view.more.adapters

import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.navigation.Navigation
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.snackbar.Snackbar
import com.magic.smartcity.R
import com.magic.smartcity.beans.HospitalPatientCard
import com.magic.smartcity.databinding.ItemHospitalPatientCardBinding

/**
 * @description:
 * @create: Create by Magic on 2022/2/19.
 */
class HospitalPatientCardAdapter : RecyclerView.Adapter<HospitalPatientCardAdapter.ItemHolder>() {

    class ItemHolder(binding: ItemHospitalPatientCardBinding) :
        RecyclerView.ViewHolder(binding.root) {
        val binding = binding
    }

    private val TAG: String = "HospitalPatientCardAdapter"
    private val list: MutableList<HospitalPatientCard> = mutableListOf()

    fun setData(data: List<HospitalPatientCard>) {
        list.clear()
        list.addAll(data)
        notifyDataSetChanged()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
        val inflate = DataBindingUtil.inflate<ItemHospitalPatientCardBinding>(
            LayoutInflater.from(parent.context),
            R.layout.item_hospital_patient_card,
            parent,
            false
        )
        return ItemHolder(inflate)
    }
    override fun onBindViewHolder(holder: ItemHolder, position: Int) {
        holder.binding.patientCard = list[position]
        //跳转修改就诊人信息
        holder.binding.root.setOnClickListener{
            val bundle = Bundle()
            bundle.putSerializable("patientCardDetail", list[position])
            Navigation.findNavController(it).navigate(R.id.action_hospitalPatientCardFragment_to_hospitalPatientCardEditFragment,bundle)
        }
        //跳转至选科室，进行挂科
        holder.binding.nextToGuhao.setOnClickListener{
            val bundle = Bundle()
            bundle.putSerializable("patientCardDetail", list[position])
            Navigation.findNavController(it).navigate(R.id.action_hospitalPatientCardFragment_to_hospitalDepartmentsFragment,bundle)
        }
    }

    override fun getItemCount()=list.size
}